package solutions.leetcode.easy

/**
 * @author lizhidong
 * <a href="https://leetcode.cn/problems/difference-between-element-sum-and-digit-sum-of-an-array/">2535. 数组元素和与数字和的绝对差</a>
 */
private class Solution2535 {
    fun differenceOfSum(nums: IntArray): Int {
        var c1 = 0
        var c2 = 0
        for (item in nums) {
            c1 += item
            for (c in item.toString()) {
                c2 += (c - '0')
            }
        }
        return Math.abs(c1 - c2)
    }
}

fun main() {
    println(
        Solution2535().differenceOfSum(
            arrayOf(
                1, 15, 6, 3
            ).toIntArray()
        )
    )
}